#!/usr/bin/env python
#coding:utf-8
import page
from sgmllib import SGMLParser
class URLLister(SGMLParser):
    def reset(self):
        SGMLParser.reset(self)
        self.urls = []
        
    def start_a(self, attrs):
        href = [v for k, v in attrs if k=='href']
        if href:
            self.urls.extend(href)
class listername(SGMLParser):
    is_a = ''
    name = []
    def start_a(self, attrs):
        self.is_a = 1

    def end_a(self):
        self.is_a = ''

    def handle_data(self, text):
        if self.is_a:
            self.name.append(text)
            
data = page.data

lister = URLLister()
lister.feed(data)
for urls in lister.urls:
    print urls

listname = listername()
listname.feed(data)
for l in listername.name:
    print l
